package io.renren.modules.base.utils;

import java.util.Map;

import org.springframework.stereotype.Component;

import jodd.http.HttpResponse;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
/**
 * @author kk
 */
@Slf4j
@Component
public class HttpRequest {

	
	/**
	 * @param dataMap  请求的数据
	 * @param url 请求url
	 * @return
	 */
	public static JSONObject httpPost(Map<String, Object> dataMap,String url){
		log.info("发送给机器云数据:"+dataMap);
		JSONObject jsonObject = null;
		//post方法和参数
		HttpResponse request = jodd.http.HttpRequest.post(url)
				                                    .form(dataMap)
				                                    .queryEncoding("UTF-8")
				                                    .send();
		String bodyText = request.bodyText();
		log.info("机器云返回:"+bodyText);
		jsonObject = JSONObject.fromObject(bodyText);
		return jsonObject;
	}
	
}